package vn.bus.bk;

import android.app.Activity;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.view.Window;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class SplashScreen extends Activity {

    boolean isRunning;

    public void onAttachedToWindow() {
	super.onAttachedToWindow();
	Window window = getWindow();
	window.setFormat(PixelFormat.RGBA_8888);
    }

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.splash_screen);
	Thread background = new Thread() {
	    @Override
	    public void run() {
		try {
		    runOnUiThread(new Runnable() {

			@Override
			public void run() {
			    // TODO Auto-generated method stub
			    startAnimations();
			}
		    });
		    Thread.sleep(5000);
		} catch (InterruptedException e) {
		    e.printStackTrace();
		} finally {
		    startActivity(new Intent

		    (SplashScreen.this, Menu.class));
		    overridePendingTransition(R.anim.fade, R.anim.hold);
		}
	    }
	};
	isRunning = true;
	background.start();
    }

    public void startAnimations() {
	Animation anim = AnimationUtils.loadAnimation(this, R.anim.alpha);
	anim.reset();
	LinearLayout l = (LinearLayout) findViewById(R.id.lin_lay);
	l.clearAnimation();
	l.startAnimation(anim);

	anim = AnimationUtils.loadAnimation(this, R.anim.translate);
	anim.reset();
	ImageView iv = (ImageView) findViewById(R.id.logo);
	iv.clearAnimation();
	iv.startAnimation(anim);

    }

    @Override
    protected void onStop() {
	// TODO Auto-generated method stub
	super.onStop();
	isRunning = false;
    }

    @Override
    protected void onPause() {
	// TODO Auto-generated method stub
	super.onPause();
	finish();
    }
}
